<div class="roles_box">
  <!-- 面包屑 -->
  <el-row>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>角色列表</el-breadcrumb-item>
    </el-breadcrumb>
  </el-row>

  <!-- 添加角色按钮 -->
  <el-row class="rolesList_box">
    <el-button class="add_box" type="warning" @click="() => this.addRolesDialog = true">添加角色</el-button>
  </el-row>

  <!-- 带有二级展开的表格 -->
  <el-table
    border
    :data="rolesList"
    style="width: 100%">
    <el-table-column type="expand">
      <template slot-scope="data">
        <el-row class="first" v-for="first in data.row.children" :key="first.id">
          <el-col :span="4">
            <el-tag closable closable @close="deleteRightsHandler(data
            .row.id, first.id)">
              {{ first.authName }}
            </el-tag>
          </el-col>
          <el-col :span="20">
            <!-- 二级权限 -->
            <el-row class="second" v-for="second in first.children" :key="second.id">
              <el-col :span="4">
                <el-tag type="warning" closable closable @close="deleteRightsHandler(data
                .row.id, second.id)">
                  {{ second.authName }}
                </el-tag>
              </el-col>
              <el-col :span="20">
                <el-col class="third" v-for="third in second.children" :key="third.id" :span="6">
                  <el-tag type="success" closable @close="deleteRightsHandler(data
                  .row.id, third.id)">
                    {{ third.authName }}
                  </el-tag>
                </el-col>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </template>
    </el-table-column>
    <el-table-column
      label="序号"
      type="index"
      width="50">
    </el-table-column>
    <el-table-column
      label="角色名称"
      prop="roleName"
      width="120">
    </el-table-column>
    <el-table-column
      label="角色描述"
      prop="roleDesc"
      width="200">
    </el-table-column>
    <el-table-column
      label="操作">
      <template slot-scope="data">
        <el-tooltip class="item" content="编辑" effect="dark" placement="left">
          <el-button circle size="mini" type="success" icon="el-icon-edit" @click="showEditRolesHandler(data.row)"></el-button>
        </el-tooltip>
        <el-tooltip class="item" content="删除" effect="dark" placement="top">
          <el-button @click="deleteRolesHandler(data.row.id)" circle size="mini" type="danger" icon="el-icon-delete"></el-button>
        </el-tooltip>
        <el-tooltip class="item" content="分配权限" effect="dark" placement="right">
          <el-button circle size="mini" type="primary" icon="el-icon-setting" @click="showRightsHandler(data.row.children, data.row.id)"></el-button>
        </el-tooltip>
      </template>
    </el-table-column>
  </el-table>

  <!-- 添加角色对话框 -->
  <el-dialog @closed="closeAddRolesDialog" title="添加角色" :visible.sync="addRolesDialog">
    <el-form :model="addRolesInfo" ref="addRoles" :rules="addRolesRules">
      <el-form-item label="角色名称" label-width="800" prop="roleName">
        <el-input v-model="addRolesInfo.roleName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="角色描述" label-width="800" prop="roleDesc">
        <el-input v-model="addRolesInfo.roleDesc" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="() => this.addRolesDialog = false">取 消</el-button>
      <el-button type="success" @click="addRoleHanddler">确认添加</el-button>
    </div>
  </el-dialog>

  <!-- 编辑角色对话框 -->
  <el-dialog title="编辑角色" :visible.sync="eidtRolesDialog">
    <el-form :model="eidtRolesInfo" ref="addRoles" :rules="addRolesRules">
      <el-form-item label="角色名称" label-width="800" prop="roleName">
        <el-input v-model="eidtRolesInfo.roleName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="角色描述" label-width="800" prop="roleDesc">
        <el-input v-model="eidtRolesInfo.roleDesc" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="() => this.eidtRolesDialog = false">取 消</el-button>
      <el-button type="success" @click="eidtRolesInfoHandler">确认编辑</el-button>
    </div>
  </el-dialog>

  <!-- 分配权限对话框 -->
  <el-dialog title="编辑角色" :visible.sync="eidtRightsDialog" @closed="closeRightsDialog">
    <!-- 树状菜单 -->
    <el-tree
      ref="rightsTree"
      v-if="eidtRightsDialog"
      :data="rightsList"
      show-checkbox
      node-key="id"
      :default-expanded-keys="expendRightsList"
      :default-checked-keys="checkedRightsList"
      :props="rightsTreeInfo">
    </el-tree>
    <div slot="footer" class="dialog-footer">
      <el-button @click="() => this.eidtRightsDialog = false">取 消</el-button>
      <el-button type="success" @click="eidtRightsInfoHandler">确认权限分配</el-button>
    </div>
  </el-dialog>
</div>
